<template>
  <div>
    <mt-header title="绑定会员" id="ji">
      <mt-button icon="back" slot="left"  @click="$router.go(-1)"></mt-button>
    </mt-header>
    <div class="co">
      <div class="ko">
        <div class="ei">尊敬的山姆会员</div>
        <div class="li">请先绑定您的会员卡</div>
      </div>
      <div id="ti">
        <input
          type="text"
          style="
            border: 0;
            border-bottom: 0 solid black;
            background: 0;
            outline: none;
          "
          placeholder="手机号"
          class="sj"
          v-model="mphone"
        />
        <hr />
        <input
          type="text"
          style="
            border: 0;
            border-bottom: 0 solid black;
            background: 0;
            outline: none;
          "
          placeholder="您的姓名"
          class="sj"
          v-model="mname"
        />
        <hr />
      </div>
        <van-button type="primary" size="large" @click="getvipto">绑定会员卡</van-button>
    </div>
  </div>
</template>
<script>
 import { MessageBox } from "mint-ui";
export default {
  data() {
    return {
      mphone:'',
      mname:''
    }
  },
  methods: {
    getvipto(){
       let phone = /^1[3-9]\d{9}$/;
      let name= /^[\u4e00-\u9fa5]{2,16}$/;
      if(name.test(this.mname)&&phone.test(this.mphone)){
        this.axios.post('/user/viplog',`mphone=${this.mphone}&mname=${this.mname}`).then(
          res=>{
           if(res.data.code==200){
           MessageBox.alert("绑定成功").then(function () {
                window.location.href = "/mymessage";
              });
              this.$store.commit("loginiy", this.mphone);
           }else if(res.data.code==201){
               MessageBox.alert("您还是不是会员,请先购买会员").then(function () {
                window.location.href = "/vip";
              });
           }
          }
        )
      }else{
       this.$toast("提示:"+"请输入正确的手机号或名字");
      }
    }
  },
}
</script>
<style  scoped >
.sj {
  margin-top: 5vw;
}
.ei {
  font-size: 14px;
  text-align: left;
  margin-top: 5vw;
}
.li {
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  margin-top: 5vw;
}
#ji {
  font-size: 18px;
  font-weight: bold;
  background-color: #fff;
  color: #000;
}
.ti {
  text-align: left;
}
.co {
  width: 90vw;
  margin: auto;
  padding-top: 5vw;
}
.yi {
  border-style: none;
  width: 90vw;
  background-color: rgb(249, 227, 206);
  color: #fff;
  padding: 3vw;
  margin-top: 10vw;
}
</style>
